package com.jumper.property.comparer.starter;

import com.jumper.property.comparer.starter.enums.ORM;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;

/**
 * 选择配置
 */
public class LogRepositoryImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        //获取注解的属性集合
        AnnotationAttributes attributes =
                AnnotationAttributes.fromMap(
                        annotationMetadata.getAnnotationAttributes(EnableBizLog.class.getName(), false));
        //设置type
        ORM select = (ORM) attributes.get("orm");
        List<String> cfgs = new ArrayList<>();
        switch (select) {
            case MYBATIS:
                cfgs.add(MybatisBusLogAutoConfiguration.class.getName());
                break;
            case JPA:
                cfgs.add(JpaLogAutoConfiguration.class.getName());
                break;
        }
        return cfgs.toArray(new String[cfgs.size()]);
    }
}
